package com.chuangfeng.framework.core.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Criterion;

import com.chuangfeng.framework.core.common.page.Pagination;

/**
 * 
 * 底层通用数据库访问对象（DAO)BaseDaoImpl的接口定义：CURD操作
 * <code>所有DAO的祖先接口</code>
 * 
 * @author xiedy
 * 
 */
public interface BaseDao<T extends Serializable> {

	public T load(Serializable id, boolean lock);

	public T get(Serializable id);

	public T load(Serializable id);

	public T update(T entity);

	public T saveOrUpdate(T entity);
	
	public T merge(T entity);
	
	public void remove(T entity);
	
	public T removeById(Serializable id);
	
	public void removeAll(Collection entities);
	
	public List<T> removeAllByIds(List<Serializable> ids);
	
	public List<T> getAll(String orderBy, boolean isAsc);
	
	public List<T> getAll();
	
	public void saveOrUpdateAll(Collection entities);
	
	public T save(T entity) ;
	
	public void flush() ;
	
	public void clear();
	
	public void refresh(T entity);
	
	
	public List<T> find(String hql, Object... values);
	
	public List<T> find(final String hql,final int begin,final int maxSiz,Object... values);
	
	public List<T> findByProperty(String propertyName, Object value);
	
	public  List<T> findByProperty(String propertyName, Object value, String orderBy, boolean isAsc);
	
	public  T findUniqueByProperty(String propertyName, Object value);
	
	public  boolean isUnique(Object entity, String uniquePropertyNames);
	
	public T createNewEntiey();
	
	public Serializable getId(Object entity) ;
	
	public String getIdName() ;
	
	
	public Query createQuery(String hql, Object... values);
	
	public  Criteria createCriteria(Criterion... criterions);
	
	public  Criteria createCriteria(String orderBy, boolean isAsc, Criterion... criterions);
	
	
	public int getRecordCountBySQL(String sql) ;
	
	public Object uniqueResultBySQL(String sql) ;
	
	public Object uniqueResultByHQL(String hql) ;
	
	public List<Object[]> findBySQL(String sql, int beginIndex, int size);
	
	public List<Object[]> findBySQL(String sql);
	
	public void updateBySql(String sql,Object... params);
	
	public void updateBySql(String sql);
	
	public void updateByHql(String hql);
	
	public void updateByHql(String hql,Object... params);
	
	public long countAll();
	
	public int countByProperty(String property, Object value);
	
	
	public List<Map> queryForList(final String queryString,final int begin, final int end);
	
	public List<Map> queryForList(final String sql);
	
	public Pagination searchPaginated(final String hql);
	
	public Pagination searchPaginated(final String hql,final Object param);
	
	public Pagination searchPaginated(final String hql,final Object[] params);
	
	public Pagination searchPaginated(final String hql,final int offset,final int pagesize);
	
	public Pagination searchPaginated(final String hql,final Object param,final int offset,final int pagesize);
	
	public Pagination searchPaginated(final String hql,final Object[] params,final int offset,final int pagesize);
	
	public Pagination searchPaginated(Criteria criteria);
	
	public Pagination searchPaginated(Criteria criteria, int offset, int pagesize);
	
	public List<Map> getListBySql(final String sql,final int begin,final int end);
	
	public Map getOneBySql(final String sql) ;
	
	public List<Map> getListBySql(final String sql);
	

}
